package com.yunhai.device.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunhai.common.dto.GlobalException;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.utils.ObjectUtil;
import com.yunhai.common.utils.ReflectionCopy;
import com.yunhai.device.mapper.OrrOutcupStatisticsMapper;
import com.yunhai.device.service.OrrOutcupStatisticsService;
import com.yunhai.model.entity.orr.OrrOutcupStatisticsEntity;
import com.yunhai.model.vo.orr.OrrOutcupStatisticsQuery;
import com.yunhai.model.vo.orr.OrrOutcupStatisticsVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrrOutcupStatisticsServiceImpl implements OrrOutcupStatisticsService {

    @Resource
    private OrrOutcupStatisticsMapper orrOutcupStatisticsMapper;

    /**
     * 获取 OrrOutcupStatistics 分页列表
     */
    @Transactional
    public IPage getOrrOutcupStatisticsPagination(PaginationVo paginationVo, OrrOutcupStatisticsQuery orrOutcupStatisticsQuery ) throws Exception {

        IPage page = new Page( paginationVo.getPageIndex(), paginationVo.getPageSize() );
        LambdaQueryWrapper<OrrOutcupStatisticsEntity> lqs = new LambdaQueryWrapper();
        orrOutcupStatisticsMapper.selectPage(page, lqs);

        List<OrrOutcupStatisticsEntity> record = page.getRecords();
        if( !ObjectUtil.isNotEmptyList(record)){
            return page;
        }
        return page;
    }


    /**
     * 获取 OrrOutcupStatistics 所有数据
     *
     */
    @Transactional
    public List<OrrOutcupStatisticsEntity> getOrrOutcupStatisticsAllList( OrrOutcupStatisticsQuery orrOutcupStatisticsQuery ) throws Exception {

        LambdaQueryWrapper<OrrOutcupStatisticsEntity> lqs = new LambdaQueryWrapper();
        List<OrrOutcupStatisticsEntity> list = orrOutcupStatisticsMapper.selectList(lqs);
        return list;
    }


    /**
     * 获取 OrrOutcupStatistics 详情
     */
    @Transactional
    public OrrOutcupStatisticsEntity getOrrOutcupStatisticsDetail( Long id) throws Exception {

        OrrOutcupStatisticsEntity orrOutcupStatisticsEntity = orrOutcupStatisticsMapper.selectById(id);
        return orrOutcupStatisticsEntity;
    }


    /**
     * 新增 OrrOutcupStatistics
     * */
    @Transactional
    public void addOrrOutcupStatistics(OrrOutcupStatisticsVo orrOutcupStatisticsVo) throws Exception {

        OrrOutcupStatisticsEntity orrOutcupStatisticsEntity = new OrrOutcupStatisticsEntity();
        ReflectionCopy.copyProperties( orrOutcupStatisticsEntity, orrOutcupStatisticsVo );
        orrOutcupStatisticsMapper.insert(orrOutcupStatisticsEntity);
        return;
    }


    /**
     * 更新 OrrOutcupStatistics
     * */
    @Transactional
    public void updateOrrOutcupStatistics( OrrOutcupStatisticsVo orrOutcupStatisticsVo) throws Exception {

        if( orrOutcupStatisticsVo.getId() == null ){
            throw GlobalException.gen(10021, "id不存在");
        }
        OrrOutcupStatisticsEntity orrOutcupStatisticsEntity = new OrrOutcupStatisticsEntity();
        ReflectionCopy.copyProperties( orrOutcupStatisticsEntity, orrOutcupStatisticsVo );
        orrOutcupStatisticsMapper.updateById(orrOutcupStatisticsEntity);
        return;
    }

    /**
     * 删除 OrrOutcupStatistics
     * */
    @Transactional
    public void batchRemoveOrrOutcupStatistics( List<Long> ids ) throws Exception {

        if( !ObjectUtil.isNotEmptyList(ids) ){
            throw GlobalException.gen(10011, "要删除的id不存在");
        }
        orrOutcupStatisticsMapper.deleteBatchIds(ids);
    }

}